package com.abyss.bprecord.view;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.abyss.bprecord.R;
import com.abyss.bprecord.view.PopNumAdapter.OnItemClickListener;

import java.util.ArrayList;

import razerdp.basepopup.BasePopupWindow;

public class NumPop extends BasePopupWindow {
    private ArrayList<Integer> mDatas;
    private Context context;
    private onItemClickListener listener;
    private int currentNum;

    public NumPop(Context context, onItemClickListener listener, int currentNum, int start, int end) {
        super(context);
        this.context = context;
        this.listener = listener;
        this.currentNum = currentNum;
        mDatas = new ArrayList<>();
        for (int i = start; i < end; i++) {
            mDatas.add(i);
        }
        initView();
    }

    private void initView() {
        View contentView = getContentView();
        RecyclerView rv = contentView.findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(context));
        PopNumAdapter adapter = new PopNumAdapter(context, mDatas);
        adapter.setListener(new OnItemClickListener() {
            @Override
            public void ItemClicked(int num) {
                if (listener != null) {
                    listener.OnItemClicked(num);
                }
            }
        });
        rv.setAdapter(adapter);
        rv.scrollToPosition(mDatas.indexOf(currentNum));
    }

    public interface onItemClickListener {
        void OnItemClicked(int num);
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.pop_num);
    }
}
